home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ KopyRong (K) 1987. ALL RIGHTS REVERSED. */
- /* */
- /* */
- /* This module was written by Vince Perriello */
- /* with code from several authors */
- /* */
- /* */
- /* Miscellaneous routines used by BinkleyTerm */
- /* */
- /* */
- /* This software package is being distributed WITH FULL SOURCE CODE */
- /* with the following conditions: 1) If anything awful happens */
- /* because you use it (or don't use it), you accept full */
- /* responsibility; 2) you don't start making tons of voice calls to */
- /* the authors to complain or make suggestions about enhancements, */
- /* useful or otherwise; 3) you do not reuse this code in commercial */
- /* products without specific permission to do so from the authors; */
- /* 4) If you find any problems you send fixes to the authors for */
- /* inclusion in updates; 5) You find some way to express your */
- /* appreciation for this method of distribution, either by writing */
- /* code or application notes, or just sending along a "Thank You" */
- /* message. */
- /* */
- /* There is copyrighted code in this product. We either wrote it */
- /* ourselves or got permission to use it. Please don't force us to */
- /* pay a lawyer -- have some respect for our motives and don't abuse */
- /* this "license". */
- /* */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include "xfer.h"
- #include "com.h"
- #include <dos.h>
- #include <time.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <varargs.h>
-
- extern struct baud_str btypes[]; /* the baud numbers, strings */
- extern int baud,cur_baud; /* how we keep the baud rate */
- extern FILE *status_log;
- extern int got_arcmail;
- extern int loglevel;
- extern int un_attended;
- extern int fullscreen;
-
- int have_dv = 0;
- int have_ddos = 0;
- int lock_baud = 0;
-
-
- char e_input[255];
- #define NUM_STATS 6
- #define STAT_WINX 0
- #define STAT_WINY 6
- char stat_lines[NUM_STATS][65];
- int nstat_lines = 0;
- char *Loc_msg = e_input;
-
- char *_s_mdm7idunno = "I dunno";
- char *_s_mdm7giveup = "Give up";
- char *_s_mdm7toolong = "File name too long";
- char *_s_mdm7chksum = "Checksum";
-
- char *BUNDLE_msg = " Sending bundle";
- char *FIND_msg = "find";
- char *IDUNNO_msg = "???";
- char *FLAGGING_msg = " Flagging %s as sent";
- char *NOTSENT_msg = " File %s not sent";
- char *TRUNC_msg = " File %s truncated";
- char *MEMOVFL_msg = " Memory Overflow";
- char *CAN_msg = " Transfer cancelled";
- char *KBD_msg = " Keyboard Escape";
- char *TIME_msg = " Timeout";
- char *CARRIER_msg = " Lost Carrier";
- char *READ_msg = " File Read";
- char *SEEK_msg = " File Seek";
- char *NAK_msg = "NAK";
- char *FUBAR_msg = " Too many errors";
- char *CMPL_msg = "Bad block complement";
- char *CRC_msg = "CRC";
- char *EOT_msg = "EOT";
- char *SYNC_msg = "Out of Sync";
- char *CHK_msg = "Checksum";
- char *SHRT_msg = "Short block";
- char *IO_msg = "I/O Error";
- char *CREATE_msg = "Create";
- char *CLOSE_msg = "Close";
- char *UNLINK_msg = "Unlink";
- char *OPEN_msg = "Open";
- char *WRITE_msg = "Write";
- char *NOTHING_msg = " Nothing transferred";
- char *local_CEOL = "\033[K";
-
- mtask_find ()
- {
- char buff[80];
- unsigned int dv_get_version();
-
- scr_printf ("Multi-Tasker: ");
- if ((have_dv = dv_get_version ()) != 0)
- {
- sprintf (buff, "DESQview version %d.%02d\r\n",
- have_dv >> 8, have_dv & 0xff);
- }
- else if ((have_ddos = ddos_active()) != 0)
- {
- strcpy (buff, "DoubleDOS\r\n");
- }
- else
- {
- strcpy (buff, "None detected\r\n");
- }
-
- scr_printf (buff);
- }
-
- dexists(filename)
- char *filename;
- {
- struct FILEINFO dta;
- return (!dfind(&dta,filename,0));
- }
-
- dfind (dta, name, times)
- struct FILEINFO *dta;
- char *name;
- int times;
- {
- union REGS r;
-
- r.x.dx = (int)dta;
- r.h.ah = 0x1a;
- intdos (&r, &r);
- r.x.bx = 0;
- r.x.cx = ~0x08;
- r.x.dx = (int)name;
- r.x.si = 0;
- r.x.di = 0;
- if (times == 0)
- {
- r.h.ah = 0x4e;
- intdos (&r, &r);
- dta->nill = '\0';
- if (r.x.cflag != 0)
- {
- dta->name[0] = '\0';
- return (1);
- }
- return (0);
- }
- else
- {
- r.h.ah = 0x4f;
- intdos (&r, &r);
- dta->nill = '\0';
- if (r.x.cflag != 0)
- {
- dta->name[0] = '\0';
- return (1);
- }
- return (0);
- }
- }
-
-
- setmem (string,num,val)
- char *string;
- int num;
- char val;
- {
- register int i;
- for (i = 0; i < num; i++)
- *string++ = val;
- }
-
- set_baud(baudrate,log)
- unsigned baudrate;
- int log;
- {
- register int i;
-
- if (!baudrate) /* "FAST" might do this */
- return(0);
-
- if (ctl.max_baud && (baudrate > ctl.max_baud))
- baudrate = ctl.max_baud;
- else if (lock_baud)
- baudrate = ctl.max_baud;
-
- for (i = 0; btypes[i].str != NULL; i++)
- {
- if (atoi(btypes[i].str) == baudrate)
- {
- if (baud != i) /* same as what we have? */
- {
- if (log && !un_attended)
- status_line("#Setting baud to %d",baudrate);
- baud = i; /* need this for ALT-B */
- MDM_ENABLE(btypes[baud].rate);
- cur_baud = baudrate;
- }
- if (un_attended && fullscreen)
- {
- gotoxy (73, 11);
- cprintf ("%-5d", baudrate);
- }
- return(1);
- }
- }
- return(0);
- }
-
- static char *specifiers = "!*+:# ";
- static char *mon[12] = {
- "Jan","Feb","Mar","Apr","May","Jun",
- "Jul","Aug","Sep","Oct","Nov","Dec"
- };
- static struct tm *tp;
- static time_t ltime;
-
- status_line(va_alist)
- va_dcl
- {
- char *fmt;
- va_list arg_ptr;
- int i;
- extern int errno;
- extern char *strchr();
-
- va_start(arg_ptr);
- fmt = va_arg(arg_ptr, char *);
- errno = 0;
- vsprintf(e_input,fmt,arg_ptr);
- time(<ime);
- tp = localtime(<ime);
- if ((!fullscreen) || (!un_attended))
- {
- cprintf("\r\n%c %02i %03s %02i:%02i:%02i BINK %s",e_input[0],
- tp->tm_mday,mon[tp->tm_mon],tp->tm_hour,tp->tm_min,tp->tm_sec,
- &e_input[1]);
- }
- else
- {
- sprintf (stat_lines[nstat_lines], "%c %02i:%02i:%02i %-48.48s\r\n", e_input[0],
- tp->tm_hour, tp->tm_min, tp->tm_sec, &e_input[1]);
- fill_in_status();
- if (++nstat_lines == NUM_STATS)
- nstat_lines = 0;
- }
- if ((status_log != NULL) &&
- ((strchr (specifiers, e_input[0]) - strchr(specifiers,'!')) <= loglevel))
- {
- fprintf (status_log, "%c %02i %03s %02i:%02i:%02i BINK %s\n",e_input[0],
- tp->tm_mday,mon[tp->tm_mon],tp->tm_hour,tp->tm_min,tp->tm_sec,
- &e_input[1]);
- fflush (status_log);
- real_flush (fileno(status_log));
- }
-
- /*locate_x = wherex();
- locate_y = wherey();*/
- va_end(arg_ptr);
- }
-
- /*--------------------------------------------------------------------------*/
- /* THROUGHPUT */
- /* Print throughput message at end of transfer */
- /*--------------------------------------------------------------------------*/
- void pascal throughput(opt, bytes)
- int opt;
- unsigned long bytes;
- begin
- static byte *scrn = "+CPS: %lu (%lu bytes) Efficiency: %lu%%";
- static unsigned long started = 0L;
- static unsigned long elapsed;
- static unsigned long cps;
-
- if (!opt) started = time(NULL);
- else if (started)
- begin
- elapsed = time(NULL) - started;
- if ((bytes < 1024L) || (elapsed == 0L)) return;
- cps = bytes / elapsed;
- started = (cps * 1000L) / ((long )cur_baud);
- status_line(scrn,cps,bytes, started);
- end
-
- end /* throughput */
-
-
-
- fill_in_status()
- {
- int i;
-
- time(<ime);
- tp = localtime(<ime);
- gotoxy (STAT_WINX, STAT_WINY);
- for (i = nstat_lines+1; i < NUM_STATS; i++)
- {
- cputs (stat_lines[i]);
- }
- for (i = 0; i <= nstat_lines; i++)
- {
- cputs (stat_lines[i]);
- }
- gotoxy (69,8);
- cprintf ("%02i:%02i:%02i", tp->tm_hour, tp->tm_min, tp->tm_sec);
- gotoxy (69,9);
- cprintf ("%02i %03s %02i", tp->tm_mday, mon[tp->tm_mon], tp->tm_year);
- }
-
- got_error(string1,string2)
- char *string1,*string2;
- {
- extern int errno;
- if (errno == 0x18)
- errno = 0;
- if (errno != 0)
- {
- scr_printf("Can't ");
- scr_printf(string1);
- WRITE_ANSI(' ');
- scr_printf(string2);
- WRITE_ANSI('\n');
- errno = 0;
- return(1);
- }
- return(0);
- }
-
- set_xy(string)
- char *string;
- {
- WRITE_ANSI('\r');
- WRITE_ANSI('\n');
- if (*string != '\0')
- {
- scr_printf(string);
- }
- locate_x = wherex();
- locate_y = wherey();
- }
-
- message(string)
- char *string;
- {
- gotoxy(locate_x,locate_y);
- if (*string != '\0')
- scr_printf(string);
- }
-
- time_release()
- {
- if (have_dv)
- {
- dv_pause();
- }
- else if (have_ddos)
- {
- ddos_pause();
- }
- }
-
- n_disable()
- {
- }
-
- adios(n)
- int n;
- {
- MDM_DISABLE();
- exit(n);
- }
-
- brk_disable()
- {
- }
-
- clearbrk()
- {
- }
-
- fancy_str(string)
- char *string;
- {
- register int flag = 0;
- while (*string)
- {
- if (isalpha(*string)) /* If alphabetic, */
- {
- if (flag) /* already saw one? */
- *string = tolower(*string); /* Yes, lowercase it */
- else
- {
- flag = 1; /* first one, flag it */
- *string = toupper(*string); /* Uppercase it */
- }
- }
- else /* if not alphabetic */
- flag = 0; /* reset alpha flag */
- string++;
- }
- }
-
- timer(interval)
- int interval;
- {
- long timeout,timerset();
- timeout = timerset (interval * 10);
- while (!timeup(timeout))
- time_release();
- }
-
- big_pause(secs)
- int secs;
- {
- long timeout,timerset();
- timeout = timerset (secs * 100);
- while (!timeup(timeout))
- {
- if (CHAR_AVAIL())
- exit;
- time_release();
- }
- }
-
- unsigned int com_getc (t)
- int t;
- {
- unsigned char c;
- long t1;
- extern long timerset();
-
- if (CHAR_AVAIL())
- {
- c = MODEM_IN();
- }
- else
- {
- t1 = timerset (t * 100);
- while (!CHAR_AVAIL())
- {
- if (timeup (t1))
- {
- return (EOF);
- }
-
- /* This should work because we only do TIMED_READ when we have carrier */
- if (!CARRIER)
- {
- return (EOF);
- }
- time_release();
- }
- c = MODEM_IN();
- }
- return (c);
- }
-
- /* Z F R E E -- Return total number of free bytes on drive specified */
-
- long zfree(drive)
- char *drive;
- {
- union REGS r;
-
- int driveno;
- long stat;
-
- if (drive[0] != '\0' && drive[1]== ':' )
- {
- driveno = islower(*drive) ? toupper(*drive) : *drive;
- driveno = driveno - 'A' + 1;
- }
- else
- driveno = 0; /* Default drive */
-
- r.x.ax = 0x3600; /* get free space */
- r.h.dl = driveno; /* on this drive */
- int86(0x21,&r,&r); /* go do it */
-
- if (r.x.ax == 0xffff) /* error return?? */
- return(0);
-
- stat = (long)r.x.dx /* dx = clusters avail */
- * (long)r.x.ax /* ax = sectors/clust */
- * (long)r.x.cx; /* cx = bytes/sector */
-
- return(stat);
- }
-
- #ifdef NO_CRC_ASM
- /*
- * This function calculates the CRC used by the XMODEM/CRC Protocol
- * The first argument is the current CRC accumulator
- * The second argument is the next byte to add into the CRC
- * The function returns an integer which contains the CRC.
- * The low order 16 bits are the coefficients of the CRC.
- */
- unsigned int crc_update(crc, b)
- unsigned int crc;
- unsigned char b;
- {
- register newcrc;
- int i;
-
- newcrc = crc ^ (int)b << 8;
- for (i = 0; i < 8; ++i)
- if (newcrc & 0x8000)
- newcrc = newcrc << 1 ^ 0x1021;
- else
- newcrc = newcrc << 1;
- return (newcrc & 0xFFFF);
- }
- #endif
-
- scr_printf(string)
- char *string;
- {
- while (*string != 0)
- WRITE_ANSI(*string++);
- }
-
- void send_can()
- begin
- int i;
- for(i=0; i<10; i++) SENDBYTE(CAN);
- for(i=0; i<10; i++) SENDBYTE(BS);
- end
-
- invent_pkt_name(string)
- char string[];
- {
- struct tm *tp;
- time_t ltime;
- time(<ime);
- tp = localtime(<ime);
- sprintf(string,"%02i%02i%02i%02i.pkt",
- tp->tm_mday,tp->tm_hour,tp->tm_min,tp->tm_sec);
- }
-
- static char *suffixes[8] = {
- "SU", "MO", "TU", "WE", "TH", "FR", "SA", NULL
- };
-
- is_arcmail (p, n)
- char *p;
- int n;
- {
- int i;
- char c[128];
-
- if (!isdigit (p[n]))
- {
- return (0);
- }
-
- strcpy (c, p);
- strupr (c);
-
- for (i = n - 11; i < n - 3; i++)
- {
- if ((!isdigit(c[i])) && ((c[i] > 'F') || (c[i] < 'A')))
- return(0);
- }
-
- for (i = 0; i < 7; i++)
- {
- if (strnicmp (&c[n-2], suffixes[i], 2) == 0)
- break;
- }
-
- if (i >= 7)
- {
- return(0);
- }
-
- got_arcmail = 1;
- return (1);
- }
-